"use strict";
/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
const NUM_SETIME_CONST = 1000;
const NUM_LOOP_COUNT_CONST = 80;
let inDebug = false;
function log(str) {
    if (inDebug) {
        console.log(str);
    }
}
function currentTimestamp13() {
    return Date.now();
}
function ack(m, n) {
    if (m === 0) {
        return n + 1;
    }
    if (n === 0) {
        return ack(m - 1, 1);
    }
    return ack(m - 1, ack(m, n - 1));
}
function fib(n) {
    let a = 2;
    if (n < a) {
        return 1;
    }
    return fib(n - a) + fib(n - 1);
}
function tak(x, y, z) {
    if (y >= x) {
        return z;
    }
    return tak(tak(x - 1, y, z), tak(y - 1, z, x), tak(z - 1, x, y));
}
/*
 *  @State
 *  @Tags Jetstream2
 */
class Benchmark {
    /**
     * @Benchmark
     */
    run() {
        let result = 0;
        let a1 = 5;
        let a2 = 3;
        let b1 = 17.0;
        let c1 = 3;
        let c2 = 2;
        let c3 = 1;
        for (let i = 3; i <= a1; i++) {
            result += ack(a2, i);
            result += fib(b1 + i);
            result += tak(c1 * i + c1, c2 * i + c2, i + c3);
        }
        let expected = 57775;
        if (result !== expected) {
            throw new Error(`ERROR: bad result: expected ${expected} but got ${result}`);
        }
    }
}
let startTime = currentTimestamp13();
let benchMark = new Benchmark();
for (let i = 0; i < NUM_LOOP_COUNT_CONST; i++) {
    let startTimeInLoop = currentTimestamp13();
    benchMark.run();
    let endTimeInLoop = currentTimestamp13();
    //log(`controlflow-recursive: ms = ${endTimeInLoop - startTimeInLoop} i = ${i}`)
}
let endTime = currentTimestamp13();
console.log(`controlflow-recursive: ms = ${endTime - startTime}`);
